package com.xrui.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;

import java.io.IOException;


/**
 * Factory for HBase instances based on URIs.
 */
public class HBaseFactory {

    //region Singleton
    private static final HBaseFactory DEFAULT = new HBaseFactory();

    public static HBaseFactory get() {
        return DEFAULT;
    }
    //endregion

    //region Public Methods For Opening an HBase

    /**
     * Opens a HBase instance by URI.
     *
     * @param uri URI specifying the HBase instance to open.
     * @return the specified HBase instance.
     * @throws IOException on I/O error.
     */
    public HBase open(HBaseURI uri) throws IOException {
        return open(uri, HBaseConfiguration.create());
    }

    /**
     * Opens a HBase instance by URI.
     *
     * @param uri  URI specifying the HBase instance to open.
     * @param conf Hadoop configuration.
     * @return the specified HBase instance.
     * @throws IOException on I/O error.
     */
    public HBase open(HBaseURI uri, Configuration conf) throws IOException {
        return new HBase(uri, conf);
    }
    //endregion

}
